<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8"/>
    <!--标识百度适应pc和mobile-->
    <meta name="applicable-device" content="pc,mobile">
    <!--禁止百度转码-->
    <meta http-equiv="Cache-Control" content="no-transform"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--启用360浏览器的极速模式-->
    <meta name="renderer" content="webkit"/>
    <!-- 强制Chromium内核，作用于其他双核浏览器 -->
    <meta name="force-rendering" content="webkit"/>
    <!--优先使用 IE 最新版本和 Chrome-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <!--避免IE使用兼容模式-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <!--针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓-->
    <meta name="HandheldFriendly" content="true"/>
    <!--搜索引擎蜘蛛-->
    <meta name="Baiduspider" content="index,follow,noarchive"/>
    <meta name="robots" content="index,follow"/>
    <!--作者及版权-->
    <meta name="author" content="Janecraft"/>
    <meta name="copyright" content="Janecraft"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
    <title>Title</title>
    <meta name="keywords" content="关键词"/>
    <meta name="description" content="描述"/>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">

    <link href="/bootstraptable/bootstrap-table.min.css" rel="stylesheet">
    <style>
        .text_bottom_border{
            border: none;
            border-bottom: 1px solid black;
        }

        .text_no_border{
            border: none;
        }
    </style>
</head>
<body>
<div class="container">
    <div style="width: 1200px;margin: 0 auto;">
        <h5 style="color: #3e79b6">您正在做的业务是：库存管理--出入库调度管理--制定入库单</h5>
    </div>

    <div class="panel panel-default">
        <form id="module_form" class="form-horizontal">
            <div class="panel-heading" style="text-align: right">
                <button type="button" id="submit_btn" class="btn btn-info">提交</button>
                <button type="button" id="fanhui_btn" class="btn btn-info">返回</button>
            </div>
            <div class="panel-body">

                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">入库单编号：</label>
                        <div class="col-sm-8">
                            <label type="text" name="gatherId" id="gatherId"
                                   class="form-control text_no_border"
                                   value=""></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">入库理由：</label>
                        <div class="col-sm-8">
                            <label type="text" name="reason" id="reason"
                                   class="form-control text_bottom_border"
                                   value=""></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">入库详情理由：</label>
                        <div class="col-sm-8">
                            <label type="text" name="reasonExact" id="reasonExact"
                                   class="form-control text_no_border"
                                   value=""></label>
                        </div>
                    </div>

                </div>
                <!--入库明细表格-->
                <table id="module_details_table" >
                </table>

                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">应入库总件数：</label>
                        <div class="col-sm-8">
                            <label  name="amountSum" id="amountSum"
                                    class="form-control text_bottom_border"
                                    value=""></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">已入库总件数：</label>
                        <div class="col-sm-8">
                            <label readonly="readonly" type="text" name="beInTotalNumber" id="beInTotalNumber" class="form-control"
                                   value=""></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">应入库总成本：</label>
                        <div class="col-sm-8">
                            <label class="form-control" id="costPriceSum" name="costPriceSum"></label>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <label class="col-sm-4 control-label">已入库总成本：</label>
                        <div class="col-sm-8">
                            <label class="form-control" id="beInTotalCost" name="beInTotalCost"></label>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>


</div>

<!-- 全局js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.6"></script>
<script src="/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/js/plugins/layer/layer.min.js"></script>

<!-- 自定义js -->
<script src="/js/hAdmin.js?v=4.1.0"></script>
<!--<script type="text/javascript" src="/js/index.js"></script>-->

<!-- 第三方插件 -->
<script src="/js/plugins/pace/pace.min.js"></script>

<!--BootstrapTable-->
<script src="/bootstraptable/bootstrap-table.min.js"></script>
<script src="/bootstraptable/locale/bootstrap-table-zh-CN.min.js"></script>
<script>
    $(function () {
        $("#module_details_table").bootstrapTable("refresh")
        // 从页面作用域取出id
        let id = localStorage.getItem("id")

        // 根据id查询对应的入库表
        $.get("/design/storageGather/storageGatherGetId", {"id": id}, function (data) {
            // 设置产品名称和产品编号的回显
            $("#module_form #gatherId").html(data.gatherId)
            if(data.reason==='R001-2'){
                $("#module_form #reasonExact").html("库存初始")
            }else if (data.reasonExact==='R001-3'){
                $("#module_form #reasonExact").html("赠送")
            }else if (data.reason==='R001-4'){
                $("#module_form #reasonExact").html("内部归还")
            }else{
                $("#module_form #reasonExact").html("其他归还")
            }
            if(data.reason==='R001-2'){
                $("#module_form #reason").html("库存初始")
            }else if (data.reason==='R001-3'){
                $("#module_form #reason").html("赠送")
            }else if (data.reason==='R001-4'){
                $("#module_form #reason").html("内部归还")
            }else{
                $("#module_form #reason").html("其他归还")
            }
            $("#module_form #amountSum").html(data.amountSum)
            $("#module_form #costPriceSum").html(data.costPriceSum)
        }, "json")

        //  根据父级序号查出所属入库明细
        $("#module_details_table").bootstrapTable({
            // 请求方式
            method: "post",
            // 内容类型：如果请求方式是post，内容类型必须是application/x-www-form-urlencoded
            contentType: "application/x-www-form-urlencoded",
            // 请求路径
            url: '/storageGather/details/listByIdDetails',
            // 数据行交替样式
            striped: true,
            // 是否是服务器端分页：server表示服务器端，client表示前端分页
            sidePagination: 'server',
            //初始化加载第一页
            pageNumber: 1,
            //是否分页
            pagination:true,
            // 单页记录数，页大小
            pageSize: 5,
            // 分页列表
            pageList: [2, 5, 10, 20],
            //刷新按钮
            // showRefresh:true,
            // 请求参数
            queryParams:function (params){
                let obj={
                    id:id,
                    pageSize: params.limit,
                    pageNo: (params.offset / params.limit) + 1,

                }
                return obj;
            },
            columns:[{
                title:"序号",
                field:"id"
            },{
                title:"产品名称",
                field:"productName"
            },{
                title:"产品编号",
                field:"productId"
            },{
                title:"应入库件数",
                field:"amount"
            },{
                title:"已入库件数",
                field:"gatheredAmount"
            },{
                title:"调度",
                field:"",
                formatter: function (value, row, index) {
                    if(row.gatherTag=='K002-2'){
                        return "完成"
                    }else{
                        let html =`<a name="diaodu"  href='javascript:addShejiDetails(${row.id},${index})'>调度</a>`
                        return html
                    }
                }
            },]
        })



    })
    //
    function addShejiDetails(id,index) {
        $("#module_details_table").bootstrapTable("refresh")

        $.get("/design/storage/cellListById", {"id": id}, function (data) {
            if(data=='correct'){
                localStorage.setItem("id", id)
                window.location = "/storage/storage_gather_in_make_listByParentIdUI"

            }else if (data==='error'){

                alert("对不起，该产品尚未分配存储空间！")
            }
        })

    }

    $("#submit_btn").click(function (){
        let storageGather={"id":localStorage.getItem("id")}
        let id = localStorage.getItem("id")
        let data=$("#module_details_table").bootstrapTable("getData")
        for (let i=0;i<data.length;i++){
            if(data[i].gatherTag=='K002-2'){
                $.ajax({
                    url: "/design/storageGather/update",
                    type: "post",
                    data: JSON.stringify(storageGather),
                    contentType: "application/json",
                    success: function (data) {
                        if(data=='correct'){
                            window.location=window.location="/storage/storage_gather_inUI"
                        }
                    }
                })
            }else{
                alert("未全调度完成，不能提交")
            }
        }
    })

    $("#fanhui_btn").click(function (){
        $("#module_details_table").bootstrapTable("refresh")
        window.location = "/storage/storage_gather_inUI"
    })
</script>
</body>
</html>
